import { produce, Draft } from 'immer';
import { useState } from 'react';
const useImmer = <T>(baseState:T):[T, (updater: (draft: Draft<T>) => void) => void]=>{
    const [ state, setState ] = useState<T>(baseState);
    const setStateWithImmer = (updater:(draft:Draft<T>)=>void)=>{
        setState(produce(state, updater));
    };

    return [ state, setStateWithImmer ];
};

export default useImmer;
